package com.maishi.programmer.jainzhioffer;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;

/**
 * Created by brossdong on 2018/4/13.
 * 统计一个数字在排序数组中出现的次数。
 */
public class TestProblem53 {

    public static int GetNumberOfK(int [] array , int k) {
        HashMap hashMap = new HashMap();
        int count = 0;
        if (array == null || array.length < 1) return 0;
        for (int i = 0;i < array.length;i++){
            hashMap.put(i,array[i]);
        }
        Collection values = hashMap.values();
        for (Iterator iterator = values.iterator(); iterator.hasNext();){
            int value = (int)iterator.next();
            if (k == value)
                count++;
        }
        return count;
    }

    public static void main(String[] args) {
        int numberOfK = GetNumberOfK(new int[]{1, 2, 3, 3, 3, 3, 4, 5}, 3);
        System.out.println(numberOfK);
    }

}
